﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Entity;
using TGBTech.Core.Models;
using TGBTech.Core.Models.ChungTu;
using TGBTech.Core.Models.DanhMuc;
using System.Data.Entity.ModelConfiguration.Conventions;

namespace TGB.Core.Infrastructure
{
    public class TGBTechDb : DbContext, ITGBTechDataSource
    {
        private const string _defaultConnectionStringName = "DefaultConnection";

        public TGBTechDb()
            : base(_defaultConnectionStringName)
        {
            
        }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            MigrateDatabaseToLatestVersion<TGBTechDb, Configuration> migrateDatabaseConfiguration = new MigrateDatabaseToLatestVersion<TGBTechDb, Configuration>();
            Database.SetInitializer(migrateDatabaseConfiguration);

            modelBuilder.Conventions.Remove<OneToManyCascadeDeleteConvention>();
            
            base.OnModelCreating(modelBuilder);

        }

        public DbSet<ChungTu> ChungTu { get; set; }
        public DbSet<CTChungTu> CTChungTu { get; set; }
        public DbSet<Data> Data { get; set; }
        public DbSet<DanhMuc> DanhMuc { get; set; }
        public DbSet<ChiTietHangHoa> ChiTietHangHoa { get; set; }
        public DbSet<KhachHang> KhachHang { get; set; }
        public DbSet<HangHoa> HangHoa { get; set; }
        public DbSet<TaiKhoan> TaiKhoan { get; set; }

        IQueryable<ChungTu> ITGBTechDataSource.ChungTu
        {
            get { return ChungTu; }
        }

        IQueryable<CTChungTu> ITGBTechDataSource.CTChungTu
        {
            get { return CTChungTu; }
        }

        IQueryable<Data> ITGBTechDataSource.Data
        {
            get { return Data; }
        }

        IQueryable<DanhMuc> ITGBTechDataSource.DanhMuc
        {
            get { return DanhMuc; }
        }

        IQueryable<ChiTietHangHoa> ITGBTechDataSource.ChiTietHangHoa
        {
            get { return ChiTietHangHoa; }
        }

        IQueryable<KhachHang> ITGBTechDataSource.KhachHang
        {
            get { return KhachHang; }
        }

        IQueryable<HangHoa> ITGBTechDataSource.HangHoa
        {
            get { return HangHoa; }
        }

        IQueryable<TaiKhoan> ITGBTechDataSource.TaiKhoan
        {
            get { return TaiKhoan; }
        }
    }
}
